package cn.echogo.ipart.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import cn.echogo.ipart.R;

public class PhotosGalleryActivity extends Activity implements OnTouchListener{
	
	private static final String tag = "PhotosGalleryActivity";
	ImageView iv;
	GestureDetector detector;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.photos_gallery);
		
		iv = (ImageView) findViewById(R.id.imageView1);
		iv.setOnTouchListener(this);
		detector = new GestureDetector(this, gestureListener);
		
	}
	
	private SimpleOnGestureListener gestureListener = new SimpleOnGestureListener(){
		public boolean onDown(MotionEvent event) {
			Log.d(tag, "onDown(" + event.getX() + "," + event.getY() + ")" + "  " + getTouchName(event.getAction()));
			return true;
		};
		public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) {
			Log.d(tag, "onScroll(" + event1.getX() + "," + event1.getY() + "), (" + event2.getX() + "," + event2.getY() + ")");
			return true;
		};
		public boolean onDoubleTap(MotionEvent event) {
			Log.d(tag, "onDoubleTap(" + event.getX() + "," + event.getY() + ")");
			return false;
		};
		public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
			Log.d(tag, "onFling(" + event1.getX() + "," + event1.getY() + "), velocity(" + velocityX + "," + velocityY + ")");
			return true;
		};
	};
	
	@Override
	public boolean onTouch(View v, MotionEvent event) {
		Log.d(tag, "onTouch(" + event.getX() + "," + event.getY() + ")" + "  " + getTouchName(event.getAction()));
		
		return detector.onTouchEvent(event);
		
	}
	
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		Log.d(tag, "onTouchEvent(" + event.getX() + "," + event.getY() + ")" + "  " + getTouchName(event.getAction()));
		return super.onTouchEvent(event);
	}
	
	private String getTouchName(int touchCode) {
		String name;
		switch (touchCode) {
		case MotionEvent.ACTION_DOWN:
			name = "down";
			break;
		case MotionEvent.ACTION_UP:
			name = "up";
			break;
		case MotionEvent.ACTION_MOVE:
			name = "move";
			break;
		case MotionEvent.ACTION_CANCEL:
			name = "cancel";
			break;
		case MotionEvent.ACTION_POINTER_DOWN:
		case 261:		//(266&ACTION_MASK==5)
		case 517:
		case 773:
			name = "pointerDown";
			break;
		case MotionEvent.ACTION_POINTER_UP:
		case 262:
		case 518:
		case 774:
			name = "pointerUp";
			break;
		default:
			name = "" + touchCode;
			break;
		}
		return name;
	}
	
}
